package com.teacher.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.teacher.common.CommonResult;
import com.teacher.mapper.TermMapper;
import com.teacher.pojo.dto.moraleducation.MoralEducationGetDto;
import com.teacher.pojo.entity.MoralEducation;
import com.teacher.mapper.MoralEducationMapper;
import com.teacher.pojo.vo.moraleducation.MoralEducationGetVo;
import com.teacher.service.IMoralEducationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 德育素质表 服务实现类
 * </p>
 *
 * @author zfm
 * @since 2021-08-03
 */
@Service
public class MoralEducationServiceImpl extends ServiceImpl<MoralEducationMapper, MoralEducation> implements IMoralEducationService {

    @Autowired
    private TermMapper termMapper;

    /**
     * 查询德育素质表
     *
     * @param dto
     * @return
     */
    @Override
    public CommonResult<IPage<MoralEducationGetVo>> getPage(MoralEducationGetDto dto) {
        Page<MoralEducationGetVo> page = new Page<>(dto.getCurrentPage(), dto.getPageSize());
        if (dto.getTermId() == null) {
            dto.setTermId(termMapper.getCurrentTerm());
        }
        IPage<MoralEducationGetVo> iPage = baseMapper.getPage(page, dto);

        return CommonResult.success(iPage);
    }
}
